#!/usr/bin/env bash
# does the following:
# - hhd Decky Plugin
VERSION=${VERSION_TAG:-"LATEST"}
if [ "$EUID" -eq 0 ]
  then echo "Please do not run as root"
  exit
fi


echo "removing previous install if it exists"

cd $HOME

sudo rm -rf "$HOME/homebrew/plugins/hhd-decky"

echo "installing hhd plugin"

FINAL_URL='https://gitee.com/api/v5/repos/songy171/hhd-decky/releases/latest'
if [ $VERSION != "LATEST" ] ; then
  FINAL_URL="https://gitee.com/songy171/hhd-decky/releases/tag/${VERSION}"
fi

curl -L https://gitee.com/songy171/hhd-decky/releases/download/v0.1.0/hhd-decky.tar.gz -o $HOME/hhd-decky.tar.gz
sudo tar -xzf hhd-decky.tar.gz -C $HOME/homebrew/plugins

# install complete, remove build dir
rm  $HOME/hhd-decky.tar.gz
sudo systemctl restart plugin_loader.service

echo "Installation complete"
